﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Licenta1.Statements
{
    class DisplayStatement : Statement
    {
        Expression Params;

        public DisplayStatement(Context context, Expression parameters)
            : base(context)
        {
            Params = parameters;
        }

        public override void Execute()
        {
            if (Params == null)
                Console.WriteLine("Nothing to display...");
            else
            {
                try
                {
                    ParameterList p_list = (ParameterList)Params;

                    Display(p_list);
                }
                catch (Exception)
                {
                    try { Console.WriteLine(((Shape)Params.Value).Display()); }
                    catch (Exception) { Console.WriteLine(Params.Value.ToString()); }
                }
            }
        }

        public void Display(ParameterList list)
        {
            if (list.FirstValue != null)
            {
                try { Console.WriteLine(((Shape)list.FirstValue).Display()); }
                catch (Exception) { Console.WriteLine(list.FirstValue.ToString()); }
            }
            if (list.SecondValue != null)
                if (list.SecondValue.GetType() != typeof(ParameterList))
                {
                    try { Console.WriteLine(((Shape)list.SecondValue).Display()); }
                    catch { Console.WriteLine(list.SecondValue.ToString()); }
                }
                else Display((ParameterList)list.SecondValue);
        }
    }
}
